//-----------------------------------------------------------------------------
//
//  <No description>
//
//  Microsoft Zenith Project
//  Copyright ©2001,2002,2003,2004 Microsoft Corporation
//  One Microsoft Way, Redmond, Washington 98052-6399 U.S.A.
//  All rights reserved.
//  MICROSOFT CONFIDENTIAL
//
//-----------------------------------------------------------------------------

#ifndef _HAG_XR16l784__GPIO_H_1
#define _HAG_XR16l784__GPIO_H_1   1

//////////////////////////////////////////////////////////////////////////////
// HAG_XR16l784_GPIO_Driver
//
struct HAG_XR16l784_GPIO_Driver
{
    enum GPIO_NAMES {
		// inputs
        COM4_CTS=104,
		COM7_CTS=105,
		COM7_DSR=106,
		COM7_DCD=107,
		COM7_RI=108,
		
		// outputs
		COM4_RTS=112,
		COM6_DUPLEX=113,
		COM7_RTS=114,
		COM7_DTR=115,
    };

    //--//

	static const unsigned c_FirstIo = COM4_CTS;
	static const unsigned c_Inputs = 5;
	static const unsigned c_Reserved = 3;
	static const unsigned c_Outputs = 4;
	static const unsigned c_MaxPins = c_Inputs+c_Reserved+c_Outputs;
	static const UINT32   c_InitDone = 0xff66532b;
	static const UINT8    c_Gpio_Attributes[c_MaxPins];

    //--//


	struct PIN_ISR_DESCRIPTOR
    {
        GPIO_INTERRUPT_SERVICE_ROUTINE code;
        void*                          data;
		int							   mode;
    } m_IsrCallbacks[c_Inputs];

	UINT32             		m_PinReservationInfo[c_MaxPins];
    BOOL			   		m_IOMap[c_MaxPins];
	BOOL			   		m_IOMap_Old[c_MaxPins];
	UINT32   				m_InitDone;

	//--//

    static BOOL Initialize  ();
    static BOOL Uninitialize();
    static UINT32 Attributes( GPIO_PIN Pin );
    static void DisablePin( GPIO_PIN Pin, GPIO_RESISTOR ResistorState, UINT32 direction, GPIO_ALT_MODE AltFunction );
    static void EnableOutputPin( GPIO_PIN Pin, BOOL InitialState );
    static BOOL EnableInputPin( GPIO_PIN Pin, BOOL GlitchFilterEnable, GPIO_INTERRUPT_SERVICE_ROUTINE ISR, void* ISR_Param, GPIO_INT_EDGE IntEdge, GPIO_RESISTOR ResistorState );
    static BOOL GetPinState( GPIO_PIN Pin );
    static void SetPinState( GPIO_PIN Pin, BOOL PinState );
    static void SetResistor( GPIO_PIN Pin, GPIO_RESISTOR ResistorState );
    static BOOL PinIsBusy( GPIO_PIN Pin );
    static BOOL ReservePin( GPIO_PIN Pin, BOOL fReserve );
    static UINT32 GetDebounce();
    static BOOL SetDebounce( INT64 debounceTimeMilliseconds );
    static void GetPinsMap( UINT8* pins, size_t size );
private:
	static void UARTCallback(int com, int pin, bool val, void *param);
};

extern HAG_XR16l784_GPIO_Driver g_HAG_XR16l784_GPIO_Driver;
//
// HAG_XR16l784_GPIO_Driver
//////////////////////////////////////////////////////////////////////////////
#endif
